package com.fxd.crm.web.controller.course;

import com.fxd.crm.model.CourseOrder;
import com.fxd.crm.model.PageResult;
import com.fxd.crm.model.course;
import com.fxd.crm.model.curdResult;
import com.fxd.crm.service.ICourseOrderService;
import com.fxd.crm.service.ICourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther fuxudong
 * @date 2021/4/5 - 9:00
 */
@RestController
@RequestMapping("/course")
public class courseBodyController {
    @Autowired
    ICourseService courseService;

    /**
     * page:显示当前页
     * limit：每次显示多少条
     *
     * @return
     */
    @RequestMapping("listjson")
    public PageResult<course> listJson(course course, int page, int limit) {
        PageResult<course> pageResult = courseService.findPageResult(course, page, limit);
        return pageResult;
    }

    @RequestMapping("save")
    public curdResult save(course course) {
        curdResult curdResult;
        if (course.getCourse_id() != null) {
            System.out.println();
            curdResult = new curdResult(1, "成功");
            courseService.update(course);
        } else {
            curdResult = new curdResult(1, "成功");
            courseService.save(course);
        }
        return curdResult;
    }

    @RequestMapping("delete")
    public curdResult delete(Integer course_id) {
        curdResult curdResult = new curdResult();
        courseService.deleteByOrderId(course_id);
        return curdResult;

    }

}
